package com.hz.ruoyiequipment.data.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.ruoyiequipment.data.domain.vo.CqEquipment;
import com.hz.ruoyiequipment.data.domain.vo.CqTimeData;
import com.hz.ruoyiequipment.data.mapper.AgrEquipmentCqMapper;
import com.hz.ruoyiequipment.data.mapper.AgrEquipmentMapper;
import com.hz.ruoyiequipment.data.service.AgrEquipmentCqService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: xqd
 * @CreateDate: 2025/03/09/16:54
 * @Description:
 */
@Service
public class AgrEquipmentCqServiceImpl extends ServiceImpl<AgrEquipmentCqMapper, CqEquipment> implements AgrEquipmentCqService {
    @Autowired
    private AgrEquipmentCqMapper agrEquipmentCqMapper;
    @Autowired
    private AgrEquipmentMapper agrEquipmentMapper;
    @Override
    @Transactional
    public AjaxResult updateAgrEquipmentCq(CqEquipment cqEquipment) {
        agrEquipmentMapper.updateAgrEquipmentCq(cqEquipment);
        agrEquipmentCqMapper.updateAgrEquipmentCq(cqEquipment);
        Integer equipmentId = agrEquipmentCqMapper.getEquipmentId(cqEquipment.getEquipmentId());
        if (equipmentId == null){
            if (cqEquipment.getPlotsId() != null){
                agrEquipmentCqMapper.insertAgrEquipmentPlot(cqEquipment);
            }
        } else {
            agrEquipmentCqMapper.updateAgrEquipmentPlot(cqEquipment);
        }
        return AjaxResult.success();
    }

    @Override
    @Transactional
    public AjaxResult delAgrEquipmentCqByEquipmentId(Long equipmentId) {
        agrEquipmentMapper.delAgrEquipmentByEquipmentId(equipmentId);
        agrEquipmentCqMapper.delAgrEquipmentCqByEquipmentId(equipmentId);
        agrEquipmentCqMapper.delAgrEquipmentPlotByEquipmentId(equipmentId);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult getCqTimeData(Long equipmentId) {
         return AjaxResult.success(agrEquipmentCqMapper.getCqTimeData(equipmentId));
    }

    @Override
    public AjaxResult getCqTimeDatas(Long equipmentId) {

        return AjaxResult.success(agrEquipmentCqMapper.getCqTimeDatas(equipmentId));
    }

    @Override
    public AjaxResult getCqTimeDataHead(Long equipmentId) {
         return AjaxResult.success(agrEquipmentCqMapper.getCqTimeDataHead(equipmentId));
    }

    @Override
    public AjaxResult insertCqTimeData(CqTimeData cqTimeData) {
         agrEquipmentCqMapper.insertCqTimeData(cqTimeData);
         return AjaxResult.success();

    }


}
